# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Project Name: luffcity study project
File Name: common_interface.py
公用的经常复用的方法
Author: kij
Create Date: 2021/2/22
-------------------------------------------------
"""
import os
import pickle
from modle.modles import Admin, School, Teacher, Student,Lesson
from conf.setting import BASE_DIR

# 所有登陆合并
def all_logon(user_name, user_password, user_type):
	if user_type == "admin":
		obj = Admin.get_data(user_name)
	if user_type == "student":
		obj = Student.get_data(user_name)
	if user_type == "teacher":
		obj = Teacher.get_data(user_name)
	if obj:
		if user_password == obj.user_password:
			return True, '登陆成功'
		else:
			return False, '密码错误'
	else:
		return False, '用户不存在'


# 获取全部机构
def get_all_school(admin_name=None):
	file_path = os.path.join(BASE_DIR, "files", "School")
	school_name_list = os.listdir(file_path)
	school_class_list = []
	for item in range(len(school_name_list)):
		# 得到全部文件然后对比admin_name 是否为当前人信息
		if admin_name == School.get_data(school_name_list[item]).admin_name:
			school_class_list.append(School.get_data(school_name_list[item]))
		if admin_name == None:
			school_class_list.append(School.get_data(school_name_list[item]))
	return school_class_list

# 得到所有数据中课程的名称
def get_all_lesson(school_name):
	file_path = os.path.join(BASE_DIR, "files", "Lesson")
	lesson_name_list = os.listdir(file_path)
	lesson_class_list = []
	for item in range(len(lesson_name_list)):
		# 得到全部文件然后对比admin_name 是否为当前人信息
		if school_name == Lesson.get_data(lesson_name_list[item]).school_name:
			lesson_class_list.append(Lesson.get_data(lesson_name_list[item]))
		if school_name == None:
			lesson_class_list.append(School.get_data(lesson_name_list[item]))
	return lesson_class_list



def get_all_teacher():
	print("获取全部学校老师")
	pass




def get_all_student():
	print("获取全部学校学生")
	pass
